package com.itcsystem.manager;

import com.itcsystem.connection.ConnectionUtility;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import com.itcsystem.struct.Generacion;

public class GeneracionManager{
	private ConnectionUtility connectionUtility = ConnectionUtility.getConnectionUtility();

	public Integer insertGeneracion(Generacion generacion){
		String sql = "INSERTGENERACION ?,?,?";
	
		List<Object> parameters = new ArrayList<Object>();
		parameters.add(generacion.getFechaInicio());
		parameters.add(generacion.getFechaFinal());
		connectionUtility.buildPreparedStatement(sql, parameters, true);
		
		return connectionUtility.executeSQLInsert();
	}
	public Boolean deleteGeneracion(int idGeneracion){
		String sql = "DELETEGENERACION ?";
		connectionUtility.buildPreparedStatement(sql, idGeneracion);
	
		return connectionUtility.executeSQLDelete();
	}
	public List<Generacion> getGeneracions(){
		List<Generacion> listGeneracion = new ArrayList<Generacion>();
		String sql = "SELECTGENERACION";
	
		try{
			ResultSet resultSet = connectionUtility.getResult(sql);
		
			if (resultSet !=null){
				while(resultSet.next()){
					Generacion obj = new Generacion();
		
					obj.setFechaInicio((java.sql.Date)resultSet.getObject("FechaInicio"));
	
					obj.setFechaFinal((java.sql.Date)resultSet.getObject("FechaFinal"));
	
					obj.setId((int)resultSet.getObject("Id"));
	
					
					listGeneracion.add(obj);
				}
			}
		}
		catch(SQLException ex){
			ex.printStackTrace();
		}
	
		return listGeneracion;
	}
}
